const api = require('../../utils/api');

Page({
    data: {
        hasSetPayPassword: false,
        hasBindStore: false,
        hasBindWeixin: false,
        hasLiveRoomAuth: false,
        bindStoreInfo: '',
    },
    onLoad(options) {

    },
    onShow() {
        this.getUserInfo();
    },

    getUserInfo() { //获取用户信息
        api.post('/user/info', {
            queryLiveSkuAuth: true
        })
            .then(res => {
                this.setData({
                    hasSetPayPassword: res.isSetPayPassword == 1 ? true : false,
                    hasBindStore: res.bindShopId || res.bindShopName ? true : false,
                    hasBindWeixin: res.isWxBound == 1 ? true : false,
                    hasLiveRoomAuth: res.liveSkuAuthFlag,
                    bindStoreInfo: res.bindShopName,
                })
            })
    },
    // 个人管理菜单
    gotoEditInfo() { //去修改个人信息
        wx.navigateTo({
            url: '/pages/userInfo/userInfo',
        });
    },
    gotoSetPassword() { //去设置支付密码
        let url = '/pages/setPayPassword/setPayPassword';
        if(this.data.hasSetPayPassword) {
            url = url + '?type=1';
        }
        wx.navigateTo({
            url: url,
        });
    },
    gotoInvite() { //去邀请好友
        wx.navigateTo({
          url: '/pages/invitation/invitation',
        });
    },
    // 店铺管理菜单
    gotoBindStore() { //去绑定店铺
        if(this.data.hasBindStore) {
            wx.navigateTo({
                url: '/pages/bindStore/bindStore?type=1',
            });
        } else {
            wx.navigateTo({
                url: '/pages/bindStore/bindStore',
            });
        }
    },
    gotoBindWeixin() { //去绑定微信公众号
        wx.navigateTo({
            url: '/pages/setMessage/setMessage',
        });
    },
    viewStoreOrder() { //查看店铺订单
        wx.navigateTo({
            url: '/pages/storeOrder/storeOrder',
        });
    },
    viewStoreReport() { //查看店铺报表
        wx.navigateTo({
            url: '/pages/storeReport/storeReport',
        });
    },
    unBindStore() { //解绑店铺
        wx.showModal({
            title: '温馨提示',
            content: `您是否确定解绑店铺【${this.data.bindStoreInfo}】？解绑操作无法撤销！`,
            success: res => {
                if(res.confirm) {
                    api.post('/user/unbind/sysuser')
                        .then(() => {
                            wx.showToast({
                                title: '店铺解绑成功！',
                                icon: 'success',
                            });
                            this.getUserInfo();
                        })
                }
            }
        });
    },
    // 其他
    gotoSelectProduct() { //去直播间选品
        wx.navigateTo({
            url: '/pages/liveRoomProduct/liveRoomProduct',
        });
    }
})